<template>
  <div class="global-container">
    <div class="gray-line"></div>
    <template v-if="tabsActive != '99'">
      <Atable :tableData="tableData" :tableModel="tableModel">
        <template #down="{ row }">
          <i class="el-icon-s-order"></i>
          {{ row.name }}
        </template>
        <template #actions="{ row }">
          <el-button @click="view(row)" type="primary" size="small">查看</el-button>
          <el-button @click="assess(row)" type="primary" size="small">评价</el-button>
        </template>
      </Atable>
    </template>
    <template v-else>
      <CompanyQlf></CompanyQlf>
    </template>
  </div>
</template>
<script>
import Atable from '@/components/Table/Atable';
import businessApi from '@/api/business';
import CompanyQlf from '@/views/info-maintain/company-info/CompanyQlf';
export default {
  props: {
    bussType: {
      type: String,
    },
  },
  components: { Atable, CompanyQlf },
  data() {
    return {
      searchData: {
        pageNum: 1,
        pageSize: 10,
        name: null, //风险指标名称
        type: 0,
      },
      tableData: [],
      tableModel: [
        {
          type: 'index',
          label: '序号',
        },
        {
          prop: 'code',
          label: '事项编号',
        },
        {
          prop: 'name',
          label: '事项名称',
          width: '300px',
        },
        {
          prop: 'sqTime',
          label: '申请时间',
          render: (row) =>
            row.sqTime ? this.$dayjs(row.sqTime).format('YYYY-MM-DD') : '',
        },
        {
          prop: 'slTime',
          label: '审查时间',
          render: (row) =>
            row.scTime
              ? this.$dayjs(row.scTime).format('YYYY-MM-DD')
              : row.slTime
              ? this.$dayjs(row.slTime).format('YYYY-MM-DD')
              : '',
        },
        {
          prop: 'actions',
          label: '操作',
          slot: 'actions',
          width: 300
        },
      ],
      bussTypeMap: {
        5: {
          code: '500005',
          name: '水利工程质量检测单位资质认定（乙级）-常规审批制',
        },
        6: {
          code: '500006',
          name: '水利工程质量检测单位资质认定（乙级）认定-初次申领',
        },
        7: {
          code: '500012',
          name: '水利工程质量检测单位资质认定（乙级）认定-延续申请',
        },
        8: {
          code: '500013',
          name: '水利工程质量检测单位资质认定（乙级）认定-变更申请',
        },
        9: {
          code: '500014',
          name: '水利工程质量检测单位资质认定（乙级）认定-注销申请',
        },
      },
      statusMap: {
        0: '未提交',
        1: '待受理',
        2: '不予受理',
        3: '待审查',
        4: '不予许可',
        5: '准予许可',
      },
      statusTabsMap: {
        1: '5',
        2: '4',
        3: '2',
      },
    };
  },
  destroyed() {
    this.$store.commit('tabs/setTabsActive', '');
    this.$store.commit('tabs/setTabsOptions', []);
  },
  mounted() {
    this.$store.commit('tabs/setTabsActive', '1');
    this.$store.commit('tabs/setTabsOptions', [
      { label: '准予许可', value: '1' },
      { label: '不予许可', value: '2' },
      { label: '不予受理', value: '3' },
      { label: '下载证书', value: '99'},
    ]);
    this.getTable();
  },
  computed: {
    tabsActive() {
      return this.$store.state.tabs.tabsActive;
    },
  },
  watch: {
    tabsActive: {
      handler() {
        this.getTable();
      },
      deep: true,
    },
  },
  methods: {
    async getTable() {
      this.tableData = [];
      // 获取列表
      businessApi
        .getStepsList({
          pageNo: 1,
          pageSize: 10,
          // 根据tabsActive获取不同的status
          status: this.statusTabsMap[this.tabsActive],
        })
        .then((res) => {
          if (res.records) {
            const records = res.records.map((item) => {
              return {
                ...item,
                ...this.bussTypeMap[item.bussType],
              };
            });
            this.tableData = records;
          }
        });
    },
    // 查看
    view(row) {
      let type =
        +row.status > 1
          ? +row.status > 3
            ? 'process'
            : 'accept'
          : 'unhandled';
      this.$router.push({
        path: '/dockPersonalProcessMain',
        query: {
          type: type,
          id: row.id,
          bussType: row.bussType,
          userId: row.userId,
          disabled: true,
        },
      });
    },
    // 评价
    async assess(row) {
      let params = {
        id: row.id,
      };
      const res = await businessApi.getJudgeWeb(params);
      window.open(res);
    },
  },
};
</script>
<style lang="scss" scoped>
.gray-line {
}
</style>
